
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nft_shop/res/global.dart';

class MyEditorWorksBottom extends StatefulWidget {
  List listName;
  ValueChanged<int> onTap;

  MyEditorWorksBottom({Key? key,required this.listName,required this.onTap}) : super(key: key);

  @override
  State<MyEditorWorksBottom> createState() => _MyEditorWorksBottomState();
}

class _MyEditorWorksBottomState extends State<MyEditorWorksBottom> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    widget.listName.add("取消");
  }


  @override
  Widget build(BuildContext context) {

    return Container(
      height:  70 * widget.listName.length + ScreenUtil.getBottomBarH(context),
      decoration: BoxDecoration(
        color: Global.kTheme.colorBackground1,
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0)),
      ),
      child: ListView.builder(
        itemCount: widget.listName.length,
        physics: const AlwaysScrollableScrollPhysics(),
        itemBuilder: (_, index) {
          return itemView(index);
        },
      ),
    );
  }

  Widget itemView(int index){
    return InkWell(
      onTap: (){
        Get.back();
        if((widget.listName.length -1) != index){
          widget.onTap(index);
        }
      },
      child: Container(
        height: 70,
        decoration: BoxDecoration(
          border: Border(
            bottom: Divider.createBorderSide(context,
                color: Global.kTheme.colorLine, width: 1),
          ),
        ),
        child: Center(child: Text(widget.listName[index],style: TextStyle(fontSize: 15,color: Global.kTheme.textPrimary6),)),
      ),
    );
  }

}
